<script setup>
  import {ref} from "vue";

  const productArr = ref([
    {title:'奔驰',price:30,num:200},
    {title:'宾利',price:30,num:200},
    {title:'su7',price:30,num:200},
    {title:'宝马',price:30,num:200},
  ])

  const del = (i) =>{
    if (confirm('确定删除吗?')){
      // 从下标i开始,删除1个元素
      productArr.value.splice(i,1);
    }
  }
</script>

<template>
  <h1>循环指令</h1>
  <ul>
  <!--  item从1开始,每执行一次.item的值+1,一直到n  -->
  <!--  v-for的效果:执行7次,生成7个li  -->
    <li v-for="item in 7">{{item}}</li>
  </ul>
  <ul>
    <li v-for="item in productArr">{{item}}</li>
  </ul>
  <table border="1px">
    <tr>
      <th>汽车编号</th>
      <th>汽车品牌</th>
      <th>汽车价格</th>
      <th>汽车库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(item,index) in productArr">
      <!--   循环几次,就生成几个tr   -->
      <!--   index从0开始   -->
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<style scoped>

</style>